package DAO;

import java.util.List;

import org.hibernate.SessionFactory;
import org.hibernate.classic.Session;

import Beans.AreaBean;
import HibernateUtils.HibernateUtil;

public class HibernateAreaDAO {
	private static HibernateAreaDAO instancia;
	private static SessionFactory sf;

	public static HibernateAreaDAO getInstancia(){
		if(instancia==null){
			sf=HibernateUtil.getSessionFactory();
			instancia=new HibernateAreaDAO();
		}
		return instancia;
	}
	
	

	public AreaBean buscarArea(AreaBean ab) {
		Session session=sf.openSession();
		AreaBean area=(AreaBean) session.get(AreaBean.class,ab.getIdArea());
		session.close();
		return area;
	}

	public List<AreaBean> getAreas(int idSucursal) {
		Session session=sf.openSession();
		List<AreaBean>areas=session.createQuery("from AreaBean a where a.idArea=?").setInteger(0, idSucursal).list();
		return areas;
	}
}
